{extend name="common/application" /}
{block name="title"}<title id="title">店铺中心-未上架商品</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/store_center.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
.nodatas{text-align:center;padding:100px 0;width:850px;}
.nodatas img{margin:100px 0 50px 0;}
</style>
{/block}


{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix">
        <!--左菜单-->
        {include file="/common/left" /}
        <!--右内容-->
        <div class="menuContent fr">
            <div class="menuConHeader">
                <!--面包屑导航-->
                <div class="breadcrumb">
                    <p>
                        <a href="javascript:;">商品管理</a> &gt;
                        <a class="curPage" href="{:url('index/store/noshelves')}">未上架商品</a>
                    </p>
                </div>
            </div>
            <div class="menuConBody">
                <div class="courseMenu">
                    <div class="courseSelect">
                        <ul>
                            <li class="selected">
                                <a class="selectType" href="javascript:;">交易类商品</a>
                            </li>
                            <li>
                                <a class="selectType" href="javascript:;">服务类商品</a>
                            </li>
                        </ul>
                    </div>
                    <input type="hidden" id="all">
                    <div class="conBody">
                        <!-- 交易商品发布 -->
                        <div class="shelvs-main">
                            <!--查询不出数据-->

                        </div>
                        <!-- 服务商品发布 -->
                        <div class="shelvs-main hide">
                            <!--查询不出数据-->

                        </div>


                    </div>
                </div>
            </div>
            <div id="page"></div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/time.js"></script>
<script>
    $(document).ready(function () {
        $('.li2').addClass('showChild');
        $('.li20').addClass('activeMenu');
    });
    $(function () {
        $('.page').eq(1).hide();
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            postfile(1, userinfo, 0);
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    });

    function postfile(page, userinfo, she) {
        var user_login = $.base64.decode(userinfo).split(",");
        if (she == 0) {
            she = 0;
            var static = 2;
            var status = 2;
        } else {
            var static = 2;
            var status = 2;
            she = 1;
        }
        $.ajax({
            type: "get",
            url: "{:url('api/shop/noshelves')}",
            data: {'she': she, 'page': page, 'uid': user_login[0], 'static': static, 'status': status},
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    $(".shelvs-main").eq(0).html("");
                    $('#page').html("");
                    if (she == 0) {
                        if (msg.data.trading.length != 0) {
                            var html = '<div class="orders-table-th"><div class="orders-wp"><div class="orders-th th-item">' +
                                '<div class="td-inner">商品信息</div></div><div class="orders-th th-type">' +
                                '<div class="td-inner">&nbsp;</div></div><div class="orders-th th-price">' +
                                '<div class="td-inner">建议售价</div></div><div class="orders-th th-op">' +
                                '<div class="td-inner">操作</div></div></div></div>';
                            for (var i = 0; i < msg.data.trading.length; i++) {
								var money = number_format(msg.data.trading[i].store, 2, ".", ",");
                                html += '<div class="orders-box"><div style="height: auto;"><div class="clearfix order-body">' +
                                    '<div class="orders clearfix"><div class="orders-info"><p>' +
                                    '<span>' + getMyDate(msg.data.trading[i].time * 1000) + '</span>' +
                                    '<span>' + msg.data.info.name + '</span></p></div></div><div class="orders-content">' +
                                    '<div class="item-list"><div class="bundle  bundle-last "><div class="item-holder">' +
                                    '<div class="J_ItemBody item-body clearfix item-normal  first-item"><ul class="item-content clearfix">' +
                                    '<li class="orders-td td-item"><div class="td-inner"><div class="item-pic J_ItemPic img-loaded">' +
                                    '<a href="/index.php/index/trade/trade_details.html?id=' + msg.data.trading[i].id + '" target="_blank" ' +
                                    'class="J_MakePoint" data-point="tbcart.8.12">' +
                                    '<img src="/Images/tradingMarket/' + msg.data.trading[i].image + '" class="itempic J_ItemImg">' +
                                    '</a></div><div class="item-info"><div class="item-basic-info"><a href="/index.php/index' +
                                    '/trade/trade_details.html?id=' + msg.data.trading[i].id + '" ' +
                                    'target="_blank" title="" class="item-title J_MakePoint" data-point="tbcart.8.11">' + msg.data.trading[i].username + '' +
                                    '</a></div><div class="item-other-info"><div class="item-icon-list clearfix">' +
                                    '<span>交易方式：' + msg.data.trading[i].trading_name + '</span></div></div><div class="item-other-info">' +
                                    '<div class="item-icon-list clearfix"><span>行业分类：' + msg.data.trading[i].market_name + '</span></div></div>' +
                                    '</div></div></li><li class="orders-td td-type"><div class="item-props item-props-can">' +
                                    '<p class="sku-line" tabindex="0">交易类商品</p></div></li><li class="orders-td td-price">' +
                                    '<div class="td-inner"><div class="item-price price-promo-"><div class="price-content">' +
                                    '<div class="price-line"><span class="price-now">￥' + money + '起</span></div></div>' +
                                    '</div></div></li><li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"' +
                                    ' class="J_Del J_MakePoint cl-o" onclick="shelvs_goods(this,' + msg.data.trading[i].id + ')">上架商品</a>' +
                                    '<a href="javascript:;" class="J_Del J_MakePoint cl-b" onclick="edit_goods(' + msg.data.trading[i].id + ')">编辑商品</a>' +
                                    '<a href="javascript:;" class="J_Del J_MakePoint cl-bla" onclick="del_goods(' + msg.data.trading[i].id + ')">删除商品</a>' +
                                    '</div></li></ul></div></div></div></div></div></div></div></div>';
                            }
                            $(".shelvs-main").eq(0).html(html);
                            if (msg.data.trading.length == 0 || msg.data.trading.length == null) {
                                $('#page').html('');
                            } else {
                                $('#page').html(msg.data.render);
                                $("#pagination").delegate("a", "click", function () {
                                    var userinfo = $.cookie('userinfo');
                                    var num = $(this).attr("num");
                                    if (num) {
                                        postfile(num, userinfo, 0);
                                    }
                                });
								var pages = Math.ceil(msg.data.count / 3);
								$("#GO").on('click',function(){
									var king = $("#go").val();
									if(king > pages){
										layer.alert("最多输入"+pages+"页");
										return;
									}
									postfile(king, userinfo, 0);
								});
                            }
                        } else {
                            $(".shelvs-main").eq(0).append('<div class="nodatas"><img src="/static/web/images/nodatas01.png"/>' +
                                '<p>抱歉，暂无数据</p></div>');
                        }
                    } else {
                        $(".shelvs-main").eq(1).html("");
                        if (msg.data.service.count != 0) {
                            var text = '<div class="orders-table-th"><div class="orders-wp"><div class="orders-th th-item">' +
                                '<div class="td-inner">商品信息</div></div><div class="orders-th th-type">' +
                                '<div class="td-inner">&nbsp;</div></div><div class="orders-th th-price">' +
                                '<div class="td-inner">建议售价</div></div><div class="orders-th th-op">' +
                                '<div class="td-inner">操作</div></div></div></div>';
                            for (var j = 0; j < msg.data.service_count; j++) {
								var money = number_format(msg.data.service[j].price, 2, ".", ",");
                                text += '<div class="orders-box"><div style="height: auto;"><div class="clearfix order-body">' +
                                    '<div class="orders clearfix"><div class="orders-info"><p>' +
                                    '<span>' + getMyDate(msg.data.service[j].add_time * 1000) + '</span>' +
                                    '<span>' + msg.data.info.name + '</span></p></div></div><div class="orders-content">' +
                                    '<div class="item-list"><div class="bundle  bundle-last "><div class="item-holder">' +
                                    '<div class="J_ItemBody item-body clearfix item-normal  first-item"><ul class="item-content clearfix">' +
                                    '<li class="orders-td td-item"><div class="td-inner"><div class="item-pic J_ItemPic img-loaded">' +
                                    '<a href="/index.php/index/service/service_details.html?id=' + msg.data.service[j].id + '" target="_blank" ' +
                                    'class="J_MakePoint" data-point="tbcart.8.12">' +
                                    '<img src="/Images/serviceGoods/' + msg.data.service[j].pic + '" class="itempic J_ItemImg">' +
                                    '</a></div><div class="item-info"><div class="item-basic-info"><a href="/index.php/index' +
                                    '/service/service_details.html?id=' + msg.data.service[j].id + '" ' +
                                    'target="_blank" title="" class="item-title J_MakePoint" data-point="tbcart.8.11">' + msg.data.service[j].goods_name + '' +
                                    '</a></div><div class="item-other-info"><div class="item-icon-list clearfix">' +
                                    '<span></span></div></div><div class="item-other-info">' +
                                    '<div class="item-icon-list clearfix"><span>服务分类：' + msg.data.service[j].t_name + '</span></div></div>' +
                                    '</div></div></li><li class="orders-td td-type"><div class="item-props item-props-can">' +
                                    '<p class="sku-line" tabindex="0">服务类商品</p></div></li><li class="orders-td td-price">' +
                                    '<div class="td-inner"><div class="item-price price-promo-"><div class="price-content">' +
                                    '<div class="price-line"><span class="price-now">￥' + money + '</span></div></div>' +
                                    '</div></div></li><li class="orders-td td-op"><div class="td-inner"><a href="javascript:;"' +
                                    ' class="J_Del J_MakePoint cl-o" onclick="shelvs_goods(this,' + msg.data.service[j].id + ')">上架商品</a>' +
                                    '<a href="javascript:;" class="J_Del J_MakePoint cl-b" onclick="edit_goods(' + msg.data.service[j].id + ')">编辑商品</a>' +
                                    '<a href="javascript:;" class="J_Del J_MakePoint cl-bla" onclick="del_goods(' + msg.data.service[j].id + ')">删除商品</a>' +
                                    '</div></li></ul></div></div></div></div></div></div></div></div>';
							
							}
                            $(".shelvs-main").eq(1).append(text);
                            if (msg.data.service.count == 0 || msg.data.service.count == null) {
                                $('#page').html('');
                            } else {
                                $('#page').html(msg.data.service.render);
                                $("#pagination").delegate("a", "click", function () {
                                    var userinfo = $.cookie('userinfo');
                                    var num = $(this).attr("num");
                                    if (num) {
                                        postfile(num, userinfo, 1);
                                    }
									
                                });
								var pages = Math.ceil(msg.data.service.count / 3);
								$("#GO").on('click',function(){
									var king = $("#go").val();
									if(king > pages){
										layer.alert("最多输入"+pages+"页");
										return;
									}
									postfile(king, userinfo, 1);
								});
                            }
                        } else {
                            $(".shelvs-main").eq(1).append('<div class="nodatas"><img src="/static/web/images/nodatas01.png"/>' +
                                '<p>抱歉，暂无数据</p></div>');
                        }
                    }
                } else {
                    layer.msg(msg.message, {icon: 5, time: 5000});
                }
            }
        })
    }

    $(document).ready(function () {
        /*交易商品服务商品切换*/
        $(".courseSelect li").on("click", function () {
            var num = $(".courseSelect li").index(this);
            $(".courseSelect li").removeClass("selected");
            $(this).addClass("selected");
            $(".shelvs-main").hide();
            $(".shelvs-main").eq(num).show();
            var userinfo = $.cookie('userinfo');
            $("#all").val(num);
            postfile(1, userinfo, num);
        })
    });

    /*上架商品*/
    function shelvs_goods(obj, id) {
        var all = $("#all").val();
        if (all == 0) {
            var static = 1;
            var status = 1;
        } else {
            var static = 1;
            var status = 2;
        }
        layer.confirm('商品上架过程中先要经过平台审核，您确认要上架吗？', {
            btn: ['确认', '取消']
        }, function () {
            /*数据操作*/
            layer.closeAll();
            $.ajax({
                type: "get",
                url: "{:url('api/shop/goods')}",
                data: {id: id, 'all': all, 'status': status, 'static': static},
                dataType: 'jsonp',
				beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
				},
                success: function (msg) {
					layer.closeAll();
                    if (msg.code == 200) {
                        var page = $(".current").attr('num');
                        var userinfo = $.cookie('userinfo');
                        var num = $("#all").val();
                        postfile(page, userinfo, num);
                    } else {
                        layer.msg(msg.message, {icon: 5, time: 5000});
                    }
                }
            })
        }, function () {
            layer.closeAll();
        })
    }

    //删除商品
    function del_goods(id) {
        var num = "#" + $("#all").val();
        var page_id = "#" + $(".current").attr('num');
        layer.open({
            type: 2,
            title: '删除商品',
            skin: 'layui-layer-lan',
            area: ['570px', '360px'], //宽高
            content: 'del_goods.html#' + id + page_id + num
        });
    }

    //编辑
    function edit_goods(id) {
        var num = "#" + $("#all").val();
        var page_id = "#" + $(".current").attr('num');
        window.location.href = 'publish_goods.html#' + id + page_id + num
    }

</script>
{/block}
